<template>
  <div>
    <a-form-model
      :model="formData"
      :rules="rules"
      :labelCol="{ xxl: 2, xl: 3, lg: 4 }"
      :wrapperCol="{ xxl: 8, xl: 9, lg: 10 }"
      ref="form"
    >
      <h3>版权设置</h3>
      <a-form-model-item label="版权链接方式" prop="type">
        <a-radio-group :options="typeList" v-model="formData.type" />
      </a-form-model-item>

      <a-form-model-item v-if="formData.type == '0'" label="选择版权链接" prop="mobile">
        <div class="flex-y-center">
          <a-input disabled class="flex-w-1" :value="formData.mini_url && formData.mini_url.name ? formData.mini_url.name : ''" />
          <a-button class="btn" type="primary" @click="showLink = true">选择</a-button>
        </div>
      </a-form-model-item>

      <a-form-model-item v-if="formData.type == '1'" label="填写联系电话" prop="mobile">
        <a-input allowClear placeholder="填写联系电话" v-model="formData.mobile"></a-input>
      </a-form-model-item>

      <h3>版权内容设置</h3>
      <a-form-model-item label="底部版权图片">
        <div>
          <CyyuploadImg
            @uploadSuccess="
              (e) => {
                formData.logo = e.data
              }
            "
            @deleteImg="formData.logo = ''"
            :imgSrc="formData.logo"
            imgSizeText="200*200"
          ></CyyuploadImg>
        </div>
      </a-form-model-item>
      <a-form-model-item label="底部版权文字" prop="copyright">
        <a-textarea allowClear placeholder="底部版权文字" v-model="formData.copyright"></a-textarea>
      </a-form-model-item>
      <a-form-model-item label=" " :colon="false" >
        <a-button @click="submit" type="primary">保存</a-button>
      </a-form-model-item>
    </a-form-model>
    <SelectLink v-if="showLink" @onOk="onOk" @cancel="showLink = false" :isSingle="true"></SelectLink>
  </div>
</template>

<script>
import { setCopyright } from '@/api/store.js'
import { cyyUploadImg } from '@/components/CyyUi/index'
import SelectLink from '@/components/DiyNew/SelectLink/index.vue'

export default {
  components: {
    CyyuploadImg: cyyUploadImg,
    SelectLink,
  },
  props: {
    store_id: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      typeList: [
        {
          label: '一键拨号',
          value: 1,
        },
        {
          label: '商城链接',
          value: 0,
        },
      ],
      showLink: false,
      formData: {
        copyright: '',
        logo: '',
        mini_url: '',
        mobile: '',
        type: 0,
      },
      rules: {},
    }
  },
  created() {
    this.getData()
  },
  methods: {
    async getData() {
      const res = await setCopyright({ id: this.store_id })
      this.formData = res.data
    },
    onOk(e) {
      console.log(e)
      this.showLink = false
      this.formData.mini_url = e
    },
    async submit() {
      const res = await setCopyright(this.formData,'post')
      this.$message.success(res.msg)
      this.getData()
    }
  },
}
</script>

<style></style>
